<template>
  <div class="page-wrap">
    <!-- 装饰 -->
    <div class="wrap">
      <div class="element-wrap">
        <div class="item-wrap">
          <div v-for="(item,index) in decoration" :key="index" class="item">
            <div class="compoment-wrap">
              <hzx-decoration
                :type="item.type"
              >
                <div style="color: #fff;">Decoration</div>
              </hzx-decoration>
            </div>
            <div class="copy-wrap" @click="copyCode($event,item.code)">  <div>{{ item.code }}</div>  </div>
          </div>
          <div class="item">increasing...</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Clipboard from 'clipboard'
export default {
  name: 'Element',
  props: {},
  data() {
    return {
      decoration: [
        { type: 'd-type1', code: `<hzx-decoration type='d-type1' />` },
        { type: 'd-type2', code: `<hzx-decoration type='d-type2' />` },
        { type: 'd-type3', code: `<hzx-decoration type='d-type3' />` },
        { type: 'd-type4', code: `<hzx-decoration type='d-type4' />` },
        { type: 'd-type5', code: `<hzx-decoration type='d-type5' />` },
        { type: 'd-type6', code: `<hzx-decoration type='d-type6' />` },
        { type: 'd-type7', code: `<hzx-decoration type='d-type7' />` },
        { type: 'd-type8', code: `<hzx-decoration type='d-type8' />` },
        { type: 'd-type9', code: `<hzx-decoration type='d-type9' />` },
        { type: 'd-type10', code: `<hzx-decoration type='d-type10' />` },
        { type: 'd-type11', code: `<hzx-decoration type='d-type11' />` }
      ]
    }
  },
  methods: {
    /**
     * @param {Object} e 事件
     * @param {String} text 赋值内容
     */
    copyCode(e, text) {
      const clipboard = new Clipboard(e.target, { text: () => text })
      console.log('Sss')
      clipboard.on('success', (e) => {
        window.alert('复制成功')
        // 释放内存
        clipboard.off('error')
        clipboard.off('success')
        clipboard.destroy()
      })
      clipboard.on('error', e => {
        // 不支持复制
        window.alert('复制失败')
        // 释放内存
        clipboard.off('error')
        clipboard.off('success')
        clipboard.destroy()
      })
      clipboard.onClick(e)
    }
  }
}
</script>

<style lang="less" scoped>
.page-wrap{
    width: 100%;
    overflow: hidden;
}
.wrap{
    width: 100%;
    height: 100%;
    display: flex;
}
.element-wrap{
    width: 100%;
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .item-wrap{
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      margin-top: 20px;
      padding: 10px;
      .item{
       width: 50%;
       height: 250px;
       justify-content: space-around;
       display: flex;
       flex-direction: column;
       align-items: center;
      }
    }
    .compoment-wrap{
        background-color: #000000;
        width: 80%;
        margin-left:10%;
        height: 200px;
    }
    .copy-wrap{
         display: flex;
         justify-content: center;
         background-color:#000;
         border-radius: 6px;
         align-items: center;
         height: 30px;
         width: 80%;
         margin-left: 10%;
         color:#fff;
     }
}

.title{
    width:100% ;
    height: 15%;
    margin-left: 10%;
    position: relative;
    display: flex;
    font-weight: 600;
    color:#000;
    font-size: 14px;
    justify-content: space-between;
    align-items: center;
    .btns{
        display: flex;
        flex-wrap: nowrap;
        width: 70%;
        margin-right: 5%;
        justify-content: space-around;
        .btns-item{
            display: flex;
            flex-wrap: nowrap;
            align-items: center;
        }
        input{
            width: 50%;
            height: 30px;
            margin-left: 20px;
            padding: 5px 10px;
            border-radius: 10px;
        }
    }
}
.title::before{
    content: "";
    width: 5px;
    position: absolute;
    height: 35%;
    background-color: rgb(24 144 255);
    left: -10px;
}
.content{
    width: 100%;
    height: 85%;
}

</style>
